﻿using ERP.Team.RBAC.xzc;
using ERP.xzc.User;
using ERP.xzc.User.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ERP.xzc.Users
{
    public class UserService:ApplicationService,IUserService
    {
        private readonly IRepository<UserModel, int> _userrepository;

        public UserService(IRepository<UserModel, int> userrepository)
        {
            _userrepository = userrepository;
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="userdto"></param>
        /// <returns></returns>
        public  async Task<int> AddUser(UserDto userdto)
        {
            var user = ObjectMapper.Map<UserDto,UserModel>(userdto);
            var i =await _userrepository.InsertAsync(user,true);
            return i == null ? 0 : 1;
        }
        /// <summary>
        /// 查询用户
        /// </summary>
        /// <returns></returns>
        public async Task<List<UserModel>> ShowUser()
        {
            var user = await _userrepository.GetListAsync();
            return user;
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="userdto"></param>
        /// <returns></returns>
        public async Task<int> DeleteUser(int id)
        {
            var i = await _userrepository.GetAsync(m=>m.Id == id);
            return i == null ? 0 : 1;
        }
    }
}
